# -*- coding: utf-8 -*-
"""
@Time: 2025/2/22 14:40
@File: get_images_list.py
@IDE: PyCharm
@Auth: Kendrick.Kc.Guan
@Email: 509556985@qq.com
@Version: 1.0
"""


from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from apps.ipo.models import JSTOpenImage


class JSTOpenImageSerializer(serializers.ModelSerializer):
    class Meta:
        model = JSTOpenImage
        fields = '__all__'


class GetImagesList(ModelViewSet):

    queryset = JSTOpenImage.objects.all()
    serializer_class = JSTOpenImageSerializer
    search_fields = ('name', 'number', )    # 指定可搜索的字段
    filter_fields = ('name', 'number', )    # 指定过滤的字段

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())

        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(queryset, many=True)
        return Response(serializer.data)
